gdk/wayland: Convert selection mimetypes back to atoms, if needed
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 6 Dec 2022 23:35:37 +0000 (00:35 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Tue, 6 Dec 2022 23:49:18 +0000 (00:49 +0100)
Commit 0c1ea922197 took care of converting STRING/UTF8_STRING to mimetype
strings when letting selection targets known to the outer world through
wl_data_source/zwp_primary_selection_source_v1, but it missed the conversion
of those mimetypes back to the old atom strings, depending on the
application, the mimetype counterparts might not be known or handled, so
requests to paste from this app could go ignored.

Fixes: 0c1ea922197 - wayland: Translate STRING/UTF8_STRING selection atoms to mimetypes
Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5397
gdk/wayland/gdkselection-wayland.c

index 6fbdb5e50df8944489d40442eb16b0f3e8a0bc37..656e3e67da1e5b6d02b8822ac2106d1c42ea2470 100644 (file)
@@ -941,20 +941,41 @@ gdk_wayland_selection_lookup_requestor_buffer (GdkWindow *requestor)
 
 static gboolean
 gdk_wayland_selection_source_handles_target (GdkWaylandSelection *wayland_selection,
-                                             GdkAtom              target)
+                                             GdkAtom             *target)
 {
   GdkAtom atom;
+  GdkAtom string_atom, utf8_string_atom;
+  GdkAtom string_mimetype, utf8_string_mimetype;
   guint i;
 
-  if (target == GDK_NONE)
+  if (*target == GDK_NONE)
     return FALSE;
 
+  string_atom = gdk_atom_intern ("STRING", FALSE);
+  utf8_string_atom = gdk_atom_intern ("UTF8_STRING", FALSE);
+  string_mimetype = gdk_atom_intern (STRING_MIMETYPE, FALSE);
+  utf8_string_mimetype = gdk_atom_intern (UTF8_STRING_MIMETYPE, FALSE);
+
   for (i = 0; i < wayland_selection->source_targets->len; i++)
     {
       atom = g_array_index (wayland_selection->source_targets, GdkAtom, i);
 
-      if (atom == target)
+      if (atom == *target)
         return TRUE;
+
+      /* We might have converted (UTF8_)STRING to mimetypes when issuing
+       * the source.target requests, convert them back if needed.
+       */
+      if (atom == string_atom && *target == string_mimetype)
+        {
+          *target = string_atom;
+          return TRUE;
+        }
+      else if (atom == utf8_string_atom && *target == utf8_string_mimetype)
+        {
+          *target = utf8_string_atom;
+          return TRUE;
+        }
     }
 
   return FALSE;
@@ -993,7 +1014,7 @@ gdk_wayland_selection_request_target (GdkWaylandSelection *wayland_selection,
   AsyncWriteData *write_data;
 
   if (!window ||
-      !gdk_wayland_selection_source_handles_target (wayland_selection, target))
+      !gdk_wayland_selection_source_handles_target (wayland_selection, &target))
     {
       close (fd);
       return FALSE;